function Map(parseString, pairDelimiter, valueDelimiter){		
	if (parseString) {
		var map=Map.parse(parseString, pairDelimiter, valueDelimiter);
		this.keys=map.keys;
		this.values=map.values;
	} else {
		this.clear();
	}
}

Map.prototype.clear=function () {
	//Arrays cleaning
	this.keys=new Array(); 
	this.values=new Array(); 
}

//Deprecated
Map.prototype.parse=function (parseString, pairDelimiter, valueDelimiter) {
	this.clear();
	
	if (!pairDelimiter){
		pairDelimiter=";";
	}
	if (!valueDelimiter){
		valueDelimiter="=";
	}
	var pairs=parseString.split(pairDelimiter);
	if (pairs==null){
		return this;
	}
	if (pairs.length==1&&pairs[0].trim()==""){
		return this;
	}
	for (var i=0; i<pairs.length; i++){
		this.keys.push(pairs[i].substring(0,pairs[i].indexOf(valueDelimiter)));
		var value=pairs[i].substring(pairs[i].indexOf(valueDelimiter)+1, pairs[i].length);
		this.values.push(value!=null?unescape(value):"");
	}
	return this;
}

Map.prototype.getValue=function (key) {
	var index=this.indexOf(key);
	if (index!=-1){
		return this.values[index];
	}
	return null;
}

Map.prototype.getValueByIndex=function (index) {
	return this.values[index];
}

Map.prototype.setValue=function (key, value){
	var index=this.indexOf(key);
	if (index!=-1){
		this.values[this.indexOf(key)]=value;
	} else {
		this.add(key, value);
	}
}

Map.prototype.indexOf=function (key, startIndex) {

	if (!startIndex){	
		startIndex=0;	
	}
	for (var i=startIndex; i<this.keys.length; i++){
		if (this.keys[i]==key){
			return i;
		}			
		if (key["toUpperCase"]&&this.keys[i]["toUpperCase"]){
			if (this.keys[i].toUpperCase()==key.toUpperCase()){
				return i;
			}
		}
	}
	return -1;
}

Map.prototype.add=function (key, value) {
	this.keys.push(key);
	this.values.push(value);
}

Map.prototype.getValues=function (key) {
	

	var values=new Array();
	var currentIndex=this.indexOf(key, 0);
	while (currentIndex!=-1){	
		values.push(this.values[currentIndex]);
		currentIndex=this.indexOf(key, currentIndex+1);	
	}
	return values;	
}

Map.prototype.getCount=function () {
	return this.keys.length;
}

Map.prototype.toQueryString=function () {
/*
	var queryString="";
	for (var i=0; i<this.keys.length; i++){
		var paramName=this.keys[i];
		var paramValue=this.values[i];
		queryString=safeConcat(queryString, paramName+"="+escape(paramValue!=null&&paramValue!=undefined?paramValue:""), "&");	
	}*/
	
	return this.toString("&", "=", true);	
}

Map.prototype.toString=function (pairDelimiter, valueDelimiter, doEscape) {
	if (!pairDelimiter){
		pairDelimiter=";";
	}
	if (!valueDelimiter){
		valueDelimiter="=";
	}
	var str="";
	for (var i=0; i<this.keys.length; i++){
		var paramName=this.keys[i];
		var paramValue=this.values[i];
		paramValue=(paramValue!=null&&paramValue!=undefined?paramValue:"");
		if (doEscape){
			paramValue=escape(paramValue);
		}
		str=String.safeConcat(str, String.format("{0}{1}{2}", paramName, valueDelimiter, paramValue), pairDelimiter);	
	}
	
	return str;	
}



Map.parse=function (parseString, pairDelimiter, valueDelimiter){
	var map=new Map();

	if (!pairDelimiter){
		pairDelimiter=";";
	}
	if (!valueDelimiter){
		valueDelimiter="=";
	}

	var pairs=parseString.split(pairDelimiter);
	if (pairs==null){
		return map;
	}
	
	if (pairs.length==1&&pairs[0].trim()==""){
		return map;
	}
	
	for (var i=0; i<pairs.length; i++){
		map.keys.push(pairs[i].substring(0,pairs[i].indexOf(valueDelimiter)));
		var value=pairs[i].substring(pairs[i].indexOf(valueDelimiter)+1, pairs[i].length);
		map.values.push(value!=null?unescape(value):"");
	}
	return map;
}

